package com.cug.smartranch.animal.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cug.smartranch.animal.admin.dto.req.AnimalPageQueryReqDTO;
import com.cug.smartranch.animal.admin.dto.req.AnimalSaveReqDTO;
import com.cug.smartranch.animal.admin.dto.req.AnimalUpdateReqDTO;
import com.cug.smartranch.animal.admin.dto.resp.AnimalPageQueryRespDTO;
import com.cug.smartranch.animal.admin.dto.resp.AnimalQueryRespDTO;
import com.cug.smartranch.animal.admin.service.AnimalService;
import com.cug.smartranch.framework.result.Result;
import com.cug.smartranch.framework.web.Results;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 动物控制层
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "动物管理")
@RequestMapping("/api/animal-admin/animal")
public class AnimalController {

    private final AnimalService animalService;

    @Operation(summary = "用户创建动物记录")
    @PostMapping("/create")
    public Result<Void> createAnimal(@RequestBody AnimalSaveReqDTO requestParam) {
        animalService.createAnimal(requestParam);
        return Results.success();
    }

    @Operation(summary = "用户分页查询所有动物基本信息")
    @GetMapping("/select/all")
    public Result<IPage<AnimalPageQueryRespDTO>> selectAllAnimal(AnimalPageQueryReqDTO requestParam) {
        IPage<AnimalPageQueryRespDTO> list = animalService.selectAllAnimal(requestParam);
        return Results.success(list);
    }

    @Operation(summary = "查询某个动物的详情信息")
    @GetMapping("/selectOne")
    public Result<AnimalQueryRespDTO> selectOne(@RequestParam(value = "id") Long id) {
        AnimalQueryRespDTO respDTO = animalService.selectOne(id);
        return Results.success(respDTO);
    }

    @Operation(summary = "删除某个动物")
    @PostMapping("/deleteOne")
    public Result<Void> deleteOne(@RequestParam(value = "id") Long id) {
        animalService.deleteOne(id);
        return Results.success();
    }

    @Operation(summary = "修改动物的基本信息")
    @PostMapping("/updateOne")
    public Result<Void> updateOne(@RequestBody AnimalUpdateReqDTO requestParam) {
        animalService.updateOne(requestParam);
        return Results.success();
    }
}
